home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT31.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.3 KB  |  85 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 31                         
  5.                                                                               
  6.  Show how to use WGT library files - simple example with wloadsprites.       
  7.  Also demonstrates how to use lib2buf to extract any type of file.           
  8.                                                                               
  9.  ▒▒▒ PROJECT ▒▒▒                                                             
  10.  This program requires the file WGT5_WC.LIB to be linked.                    
  11.                                                                               
  12.  ▒▒▒ DATA FILES ▒▒▒                                                          
  13.  You must have the DEMO31.WGT library file in your executable directory.    
  14.                                                            WATCOM C++ VERSION 
  15. ==============================================================================
  16. */
  17.  
  18. #include <wgt5.h>
  19. #include <conio.h>
  20. #include <stdlib.h>
  21.  
  22. block sprites[2];             /* Pointers to sprites */
  23. color pal[256];               /* Our palette */
  24. short oldmode;                  /* Store previous video mode */
  25. char *buf;                    /* Pointer to a buffer for extra data */
  26.  
  27. void main(void)
  28. {
  29.  
  30.   if ( !vgadetected () )
  31.   {
  32.     printf("Error - VGA card required for any WGT program.\n");
  33.     exit (0);
  34.   }
  35.   printf ("WGT Example #31\n\n");
  36.   printf ("Files are loaded into memory from a 'library' file.\n");
  37.   printf ("Press a key to end each section of the program.\n");
  38.   printf ("\n\nPress any key to continue.\n");
  39.   getch ();
  40.  
  41.   oldmode = wgetmode ();         /* Gets the current mode */
  42.   vga256 ();                     /* Initialize graphics mode */
  43.   
  44.   setlib ("demo31.wgt");         /* Tell WGT what library file to use */
  45.   setpassword ("wgt");           /* This is the required password for DEMO31.WGT */
  46.  
  47.   /* Loads a sprite file from within DEMO31.WGT */
  48.   wloadsprites (pal, "demo31.spr", sprites, 0, 1);
  49.   wsetpalette (0, 255, pal);
  50.  
  51.   wcls (0);                      /* Clear screen with black */
  52.   do                             /* Randomly place block on screen */
  53.   {
  54.     wputblock (rand () % 300, rand () % 180, sprites[1], 0);
  55.   } while (!kbhit ());           /* Abort when key is pressed */
  56.   getch ();
  57.   wfreesprites (sprites, 0, 1);
  58.   
  59.   /* Clear the screen and load a picture of some leaves */
  60.   wcls (0);
  61.   sprites[0] = wloadbmp ("leaves.bmp", pal);
  62.   wsetpalette (0, 255, pal);
  63.   wputblock (0, 0, sprites[0], NORMAL);
  64.   getch ();
  65.   wfreeblock (sprites[0]);
  66.  
  67.   /* Clear the screen and load a PCX format picture file */
  68.   wcls (0);
  69.   sprites[0] = wloadpcx ("wgt5_wc.pcx", pal);
  70.   wsetpalette (0, 255, pal);
  71.   wputblock (0, 0, sprites[0], NORMAL);
  72.   getch ();
  73.   wfreeblock (sprites[0]);
  74.  
  75.   wsetmode (oldmode);            /* Restore initial video mode */
  76.  
  77.   buf = lib2buf ("demo31.txt"); /* Load a text file from the library file */
  78.   printf ("%s\n", buf);         /* Now display the file */
  79.   free (buf);                   /* Deallocate the buffer */
  80.  
  81.   printf ("Press any key to exit.\n");
  82.   while (!kbhit ());
  83.   getch ();
  84. }
  85.